package com.sie.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sie.demo.entity.RoleMenu;
import com.sie.demo.entity.vo.SetRoleMenuVo;
import com.sie.demo.mapper.RoleMenuMapper;
import com.sie.demo.service.RoleMenuService;
import com.sie.demo.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author liaozhifeng
 * @date 2021/8/11 10:39
 * @Version 1.0
 */
@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> implements RoleMenuService {

    @Resource
    RoleMenuMapper roleMenuMapper;
    @Override
    public List<Integer> selectRoleByUserId(Integer userId) {
        List<Integer> list = roleMenuMapper.selectMenuByRoleId(userId);
        return list;
    }

    @Override
    public Integer deleteByRoleId(Integer roleId) {
        return roleMenuMapper.deleteByRoleId(roleId);
    }

    @Override
    public Integer addMenuByRoleId(Integer roleId,String[] menuIds) {
        SetRoleMenuVo setRoleMenuVo = new SetRoleMenuVo();
        //        获取当前系统时间
        Date date = new Date();
//        添加到Oracle数据库中的时间格式为：【 年/月/日  时:分:秒 】
        java.sql.Timestamp  createTime =new java.sql.Timestamp (date.getTime());
//        将前端传来的值封装到对象中写入数据库
        setRoleMenuVo.setCreateTime(createTime);
        List list = Arrays.asList(menuIds);
        setRoleMenuVo.setRoleId(roleId);
        setRoleMenuVo.setMenuIds(list);
        return roleMenuMapper.addMenuByRoleId(setRoleMenuVo);
    }
}
